﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using SimpleJSON;
using ROSBridgeLib;
using ROSBridgeLib.std_msgs;
using ROSBridgeLib.geometry_msgs;
using UnityEngine.UI;
using System;
using ROSBridgeLib.nav_msgs;

public class Map2D : MonoBehaviour {


    private Texture2D mapTexture;
   


    public int globalWidth=4096;

    public int globalHeight=4096;

  

    bool mapInitialized=false;


    public Color obstacleColor;

    public Color unknowColor;

    public Color walkableColor;

   


    void UpdateMap(OccupancyGrid map)
    {






    }

   

    public void MapDisplay(OccupancyGrid map)
    {

        if (mapInitialized==false)
        {

            InitializeMap(map);


        }


        UpdateMap(map);



    }

    void InitializeMap(OccupancyGrid map)
    {
        
      
        mapTexture=new Texture2D(map.width,map.height);

        Sprite sprite= Sprite.Create(mapTexture, new Rect(0.0f, 0.0f, mapTexture.width, mapTexture.height), new Vector2(0f, 0f), 1.0f/map.resolution);

        GetComponent<SpriteRenderer>().sprite=sprite;

        transform.localPosition=map.info.GetOrigin().position.ToVector3();

        mapInitialized=true;

    }




}
